import request from '@/utils/request';

export async function page(params) {
  return request('/jmonkey/task/page', {
    method: 'GET',
    params
  });
}

export async function save(data) {
  return request('/jmonkey/task/save', {
    method: 'POST',
    data,
  });
}

export async function update(data) {
  return request('/jmonkey/task/update', {
    method: 'PUT',
    data,
  });
}

export async function remove(id) {
  return request(`/jmonkey/task/remove/${id}`, {
    method: 'DELETE',
  });
}

/**
 * 校验任务类是否可用
 * @param {*} data 
 * @returns 
 */
export async function checkClassName(data) {
  return request('/jmonkey/task/checkClassName', {
    method: 'POST',
    data,
  });
}

/**
 * 验证定时任务规则表达式
 * @param {*} rule 
 * @returns 
 */
export async function checkRule(rule) {
  return request('/jmonkey/task/checkRule', {
    method: 'GET',
    params: {
      rule
    }
  });
}

/**
 * 暂停定时任务
 * @param {*} data 
 * @returns 
 */
export async function pause(data) {
  return request('/jmonkey/task/pause', {
    method: 'POST',
    data,
  });
}

/**
 * 恢复定时任务
 * @param {*} data 
 * @returns 
 */
export async function resume(data) {
  return request('/jmonkey/task/resume', {
    method: 'POST',
    data,
  });
}

/**
 * 立即执行定时任务
 * @param {*} data 
 * @returns 
 */
export async function startNow(data) {
  return request('/jmonkey/task/startNow', {
    method: 'POST',
    data,
  });
}